package utils;

import java.net.InetAddress;
import java.util.Vector;

/**
 * This class represents NIC adapter wiht name, display name and list of IP addresses bound
 * to this NIC adapter.
 * 
 * @author Uros Krkic
 */
public class NICInfo {
	
	private String nicName;
	private String nicDisplayName;
	private String nicMacAddress;
	private Vector<InetAddress> addresses = null;
	
	
	public NICInfo(String nicName, String nicDisplayName, String nicMacAddress) {
		this.nicName = nicName;
		this.nicDisplayName = nicDisplayName;
		this.nicMacAddress = nicMacAddress;
		addresses = new Vector<InetAddress>();
	}
	
	
	public String getNICName() {
		return this.nicName;
	}
	
	public String getNICDisplayName() {
		return this.nicDisplayName;
	}
	
	public String getNicMACAddress() {
		return this.nicMacAddress;
	}
	
	public void addNICAddress(InetAddress address) {
		addresses.add(address);
	}
	
	public Vector<InetAddress> getNICAddresses() {
		return addresses;
	}
	
	public Vector<String> getNICAddressesAsString() {
		Vector<String> temp = new Vector<String>(addresses.size());
		for (InetAddress addr : addresses) {
			temp.add(addr.getHostAddress());
		}
		
		return temp;
	}
	
	public String toString() {
		return nicDisplayName;
	}
	
	
	/**
	 * This method checks whether the specified IP address belongs to this NICInfo object.
	 * @param address - IP address
	 * @return true, if belongs, false otherwise
	 * @author Uros Krkic
	 */
	public boolean containsAddress(String address) {
		for (InetAddress addr : addresses) {
			if ( addr.getHostAddress().equalsIgnoreCase(address) )
				return true;
		}
		return false;
	}
	
}
